package com.whoami.idmagic.idmagic

import org.apache.spark.sql.SparkSession

/**
  * v1 imei halfhour, v2onehour
  *
  * @author tzp
  * @since 2019/8/31
  */
object timebucket {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession
      .builder
      .appName(s"${this.getClass.getSimpleName}")
      .getOrCreate()
    import spark.implicits._

    val day = args(0)
    println("imei-ip-ti-spid-caid" + day)

    val d = spark.read.orc("/user/mz_spt/datalake/src/admonitor/ods_adm_bus/" + day)
    d.coalesce(400)
      .filter("md5_imei != ''")
      .withColumn("timebucket", $"timestamp" - $"timestamp" % 3600)
      .select("md5_imei", "raw_ip", "timebucket", "mz_spot_id", "mz_campaign_id")
      .groupBy("md5_imei", "raw_ip", "timebucket", "mz_spot_id", "mz_campaign_id").count()
      .write.orc("/user/mz_spt/test/tzp/com.whoami.idmagic.xunji/stagelog/v2/" + day)

    spark.close()
  }

}
